package Hello;/*


1111



*/   //银行 ATM

import java.util.Scanner;

public class ATM01 {
    //全局变量
    static String[][] users = {
            {"longlong", "123", "500"},
            {"longlong2", "1234", "5000"},
            {"longlong3", "12345", "50000"},
            {"longlong4", "123456", "50000"}

    };
    static Scanner input = new Scanner(System.in);
    static int index = 0;//账户判断  余额

    public static void main(String[] args) {
        process();

    }

    //流程
    public static void process() {
        System.out.println("欢迎");
        while (true) {
            login();
            menu();
        }
    }

    //登录
    public static void login() {
        for (int i = 0; i < 3; i++) {

            System.out.println("账号：");
            String acount = input.next();
            System.out.println("密码");
            String password = input.next();
            for (int j = 0; j < users.length; j++) {
                if (users[j][0].equals(acount) && users[j][1].equals(password)) {
                    System.out.println("登陆成功");
                    index = j;
                    return;

                }
            }
            System.out.println("登录失败，还有" + (2 - i) + "次");
        }
        System.out.println("机会用完，卡没了，换卡把");
        System.exit(0);//系统结束
    }
    //修改密码
    public static void cheng(){
       while (true) {
           System.out.println("请输入原密码;");
           String oldpassword = input.next();

           if (oldpassword.equals(users[index][1])) {
               System.out.println("请输入新密码");
               String newpassword = input.next();
               System.out.println("请再次输入密码");
               String newpassword1 = input.next();

               if (newpassword.equals(newpassword1)) {
                     if(oldpassword.equals(newpassword)){
                         System.out.println("抱歉你的新密码和老密码一样，请重新修改密码");
                         return;
                     }

                   String  old =users[index][1] ;
                     users[index][1] = newpassword;
                   System.out.println("密码修改成功");
                   System.out.println("密码修改成功请输入5重新登录");
                       return;
                       } else if(newpassword.equals(oldpassword)) {
                     System.out.println("你输入的登录密码与老密码一样不相符");
                     }

                    } else {
                    System.out.println("登录密码与原密码不相符");
                            }
       }

                }




    //菜单
    public static void menu() {

        while (true) {//死循环
            System.out.println("1,存款  2,取款 3,查询  4,转账  5,更换账号  6,退出 7,修改密码");
            int a = input.nextInt();
            if (a == 1) {
                save();

            } else if (a == 2) {
                get();


            } else if (a == 3) {
                serch();

            } else if (a == 4) {
                transfer();


            } else if (a == 5) {
                return;


            } else if (a == 6) {
                System.out.println("退出程序");
                System.exit(0);
            } else if(a==7) {
                cheng();

            }else {
                System.out.println("输入错误");
            }
        }
    }

    //存款
    public static void save() {
        System.out.println("请输入存款金额：");
        double money = input.nextDouble();
        users[index][2] = money + Double.parseDouble(users[index][2]) + "";    ///加法运算 只要有一个是字符串都变成字符串拼接
        System.out.println("存入后金额为" + users[index][2]);
    }

    //取款
    public static void get() {
        System.out.println("请输入取款金额");
        double getmony = input.nextDouble();
        if (getmony > Double.parseDouble(users[index][2])) {

            System.out.println("抱歉，你钱不够");

        } else {
            users[index][2] = Double.parseDouble(users[index][2]) - getmony + "";
            System.out.println("剩余余额" + users[index][2]);
        }
    }

    //查询
    public static void serch() {
        System.out.println("余额" + users[index][2]);
    }

    //转账
    public static void transfer() {


        System.out.println("请输入转账金额");
        double trunmony = input.nextDouble();
        if (trunmony > Double.parseDouble(users[index][2])) {
            System.out.println("抱歉，余额不足");
            return;
        }

        System.out.println("输入转账用户");
        String duiuser = input.next();
        if (duiuser.equals(users[index][0])) {
            System.out.println("不可以转个自己：");
            return;
        }
        //账号是否存在
        for (int i = 0; i < users.length; i++) {
            if (users[i][0].equals(duiuser)) {    //数组是equalS
                //扣钱
                users[index][2] = Double.parseDouble(users[index][2]) - trunmony + "";
                //加
                users[i][2] = Double.parseDouble(users[i][2]) + trunmony + "";
                System.out.println("转账成功");
                return;
            }
        }
        System.out.println("账号输入错误");
    }

}


